package Servlet2;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dididi04")
public class Servlet04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("04被访问到了");
        String username = "路飞";
//        request请求域和context方法相同作用范围不同
        ServletContext context = getServletContext();
        //给两个域添加数据
        req.setAttribute("user",username);
        context.setAttribute("user",username);
//        转发
        req.getRequestDispatcher("/dididi05").forward(req,resp);
    }
}

